package com.example.demo.controller;

import com.example.demo.entity.Girl;
import com.example.demo.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/girl")
public class GirlController {
    @Autowired
    private GirlRepository girlRepository;
    @PostMapping("/add")
    public @ResponseBody String add(@RequestParam String name, @RequestParam int age){
        System.out.println(name);
        Girl girl = new Girl(name,age);
        girlRepository.save(girl);
        return girl.toString();
    }
    @GetMapping("/all")
    public @ResponseBody Iterable<Girl> queryAll(){
        return girlRepository.findAll();
    }
    @PostMapping("/one")
    public @ResponseBody String queryOne(@RequestParam long id){
        return girlRepository.findById(id).toString();
    }

}
